local M = require "packages/mamashengde/record/Made"

local shengyan = fk.CreateSkill {
  name = "shine__shengyan",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable {
  ["shine__shengyan"] = "圣焰",
  [":shine__shengyan"] = "锁定技，你使用牌时额外结算一次，然后你消耗1点魔力或失去1点体力，对一名其他角色造成1点火焰伤害。",

  ["lose_maryoku"] = "消耗1点魔力",
  ["#shine__shengyan-choose"] = "圣焰：对一名其他角色造成1点伤害",
}

shengyan:addEffect(fk.CardUsing, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(shengyan.name) and
      not data.cancelled
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    data.additionalEffect = (data.additionalEffect or 0) + 1
    data.extra_data = data.extra_data or {}
    data.extra_data.shine__shengyan = data.extra_data.shine__shengyan or {}
    table.insert(data.extra_data.shine__shengyan, player)
  end,
})
shengyan:addEffect(fk.CardUseFinished, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return not player.dead and player:getAttackRange() > 0 and
      data.extra_data and data.extra_data.shine__shengyan and table.contains(data.extra_data.shine__shengyan, player)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {"loseHp"}
    if M.getMaryoku(player) > 0 then
      table.insert(choices, "lose_maryoku")
    end
    if room:askToChoice(player, {
      choices = choices,
      skill_name = shengyan.name,
    }) == "loseHp" then
      room:loseHp(player, 1, shengyan.name)
    else
      M.changeMaryoku(player, -1, shengyan.name)
    end
    if player.dead then return end
      local to = room:askToChoosePlayers(player, {
      targets = room:getOtherPlayers(player, false),
      min_num = 1,
      max_num = 1,
      prompt = "#shine__shengyan-choose",
      skill_name = shengyan.name,
      cancelable = true,
    })
    if #to > 0 then
      room:damage{
        from = player,
        to = to[1],
        damage = 1,
        damageType = fk.FireDamage,
        skillName = shengyan.name,
      }
    end
  end,
})

return shengyan